﻿using System;
using System.ComponentModel.DataAnnotations;
using Mandarine.MVVM.Annotation;

namespace DataBindApp1.ViewModel
{
    [PropertyDecl("Name", typeof(String), generateValidate = true)]
    [PropertyDecl("Age", typeof(int), generateValidate = true
        , defaultValue = 20
        , validateOption = "ErrorMessage=\"年齢は必須です数値で入力してください\"")]
    public partial class MyViewModel
    {
    }
    public class ValidateName : RequiredAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var result = base.IsValid(value, validationContext);
            if (result != ValidationResult.Success) return result;

            var v = new RegularExpressionAttribute(@"^[ 　]*[^ -~｡-ﾟ]*[ 　]*$");
            return v.GetValidationResult(value, validationContext);
        }
    }
    public class ValidateAgeAttribute : RequiredAttribute
    {
    }
}
